package Demo;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BT4_2Threads extends JFrame {
	Thread t1, t2;
	JPanel canvas = new JPanel();
	JButton
		b1 = new JButton("Start"), 
		b2 = new JButton("Suspend"),
		b3 = new JButton("Resume"),
		b4 = new JButton("Close");
	
	public BT4_2Threads(){
		super("Thread Demo 2");
		add(canvas, BorderLayout.CENTER);
		canvas.setBackground(Color.WHITE);
		
		JPanel panelButton = new JPanel();
		panelButton.setLayout(new FlowLayout());
		panelButton.add(b1);
		panelButton.add(b2);
		panelButton.add(b3);
		panelButton.add(b4);
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				t1.start();
				t2.start();
			}
		}
		);
		b2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				t1.suspend();
				t2.suspend();
			}
		}
		);
		b3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				t1.resume();
				t2.resume();
			}
		}
		);
		b4.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				t1.stop();
				t2.stop();
				System.exit(0);
			}
		}
		);
		add(panelButton, BorderLayout.SOUTH);
		setSize(new Dimension(400,600));
		t1 = new BT4_Thread1(canvas);
		t2 = new BT4_Thread2(canvas);
	}
	
	
	public static void main(String[] args){
		BT4_2Threads frame = new BT4_2Threads();
		frame.setVisible(true);
	}
}
